Skip to content

test: tail in tests#817

Open
john-royal wants to merge 10 commits into
mainfrom
john/test-logs-v2
Open

test: tail in tests#817
john-royal wants to merge 10 commits into
mainfrom
john/test-logs-v2

Conversation

@john-royal

@john-royal john-royal commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Deploying with Test.make({ log: true }) now streams deployed Workers' console.* output into the test console with sub-second latency — Cloudflare's tail API is too slow to be useful in tests.

const { test, beforeAll, afterAll, deploy, destroy } = Test.make({
  providers: Cloudflare.providers(),
  state: Cloudflare.state(),
  log: true, // patch console.* in deployed Workers + auto-tail the stack
});

With logging enabled, the Worker bundle's virtual entry patches console.* to mirror lines into an account-level alchemy-test-logger singleton hosting one SQLite-buffered Durable Object per {stack}/{stage}. WorkerProvider.tail streams from that DO over a websocket (buffered replay on connect + live push, deduped by row id across reconnects) when the worker's new testLogger attribute is set, and falls back to the Cloudflare tail API otherwise.

  • src/Tail.ts: tail orchestration extracted from the CLI (alchemy tail is now a thin wrapper). Deploy.deploy({ tail: true }) forks it after apply; the test harness ties the fiber to its shared scope, so logs flow from beforeAll until destroy/afterAll.
  • The logger singleton is ensured lazily in reconcile instead of via an enableTestLogging layer in Cloudflare.providers(): memoized per account per process, content-hash versioned, and guarded by the new Util/FileSemaphore.ts (a lockfile-backed, key-partitioned cross-process mutex) so concurrent vitest processes don't race putScript.
  • Worker gains a testLogger output attribute, set during reconcile and reconstructed by read from the observed ALCHEMY_TEST_LOGGER DO binding. Only set where the bundle is patchable — script:, bundle: false, and dispatch-namespace workers keep the standard tail path.

@alchemy-version-bot

alchemy-version-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/090af9c

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/090af9c

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/090af9c

@john-royal john-royal marked this pull request as ready for review July 14, 2026 17:08
@john-royal john-royal changed the title test(cloudflare): logs in tests, take 2 test: tail in tests Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant